﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Api.Filter;
using Customer.Bussiness_Service;
using Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ServiceCore;

namespace Customer.Areas.QA.Controllers
{
    [ApiController, Area("QA"), Route("/QA/[action]"), Customer_Admin]
    public class QAController : ControllerBase
    {
        private readonly Iqa_service _service;
        private readonly IToole_DI _tool;
        public QAController(Iqa_service service, IToole_DI tool)
        {
            _service = service;
            _tool = tool;
        }

        /// <summary>
        ///  绑定IC
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns> 
        [HttpGet]
        public ResultModel Ic_Bind(string mchid, string sn, string box_code)
        {
            var result = _service.Ic_Bind(mchid, sn, box_code);
            _tool.di_es.Add_Log($"==绑定IC==>请求:{Newtonsoft.Json.JsonConvert.SerializeObject(new { mchid, sn, box_code })}==>结果:{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "qabind");
            return result;
        }
        /// <summary>
        ///  绑定IC2
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel Ic2_Bind(string sn, string box_code)
        {
            var result = _service.Ic2_Bind(sn, box_code);
            _tool.di_es.Add_Log($"==绑定IC2==>请求:{Newtonsoft.Json.JsonConvert.SerializeObject(new { sn, box_code })}==>结果:{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "qabind");
            return result;
        }
        /// <summary>
        ///  IC解绑
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel Ic_unBind(string Id)
        {
            var result = _service.Ic_unBind(Id);
            _tool.di_es.Add_Log($"==IC解绑==>请求:{Newtonsoft.Json.JsonConvert.SerializeObject(new { Id })}==>结果:{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "qabind");
            return result;
        }
        /// <summary>
        ///  IC2解绑
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel Ic2_unBind(string Id)
        {
            var result = _service.Ic2_unBind(Id);
            _tool.di_es.Add_Log($"==IC2解绑==>请求:{Newtonsoft.Json.JsonConvert.SerializeObject(new { Id })}==>结果:{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "qabind");
            return result;
        }
        /// <summary>
        ///  获取生产单详情
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel get_work_order_details_model(string work_order_details_id)
        {
            var result = _service.get_work_order_details_model(work_order_details_id);
            return result;
        }
        /// <summary>
        ///  开始绑定生产单
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel start_bind_workorder(string box_code, string work_order_details_id)
        {
            var result = _service.start_bind_workorder(box_code, work_order_details_id);
            _tool.di_es.Add_Log($"==开始绑定生产单==>请求:{Newtonsoft.Json.JsonConvert.SerializeObject(new { box_code, work_order_details_id })}==>结果:{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "qabind");
            return result;
        }
        /// <summary>
        ///  解绑生产单
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel unbind_workorder(string id)
        {
            var result = _service.unbind_workorder(id);
            _tool.di_es.Add_Log($"==解绑生产单==>请求:{Newtonsoft.Json.JsonConvert.SerializeObject(new { id })}==>结果:{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "qabind");
            return result;
        }

        /// <summary>
        ///  开始绑定生产单
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultListModel<Mch_bind_record_search> get_bind_pagelist(mch_Bind_params model)
        {
            var result = _service.get_bind_pagelist(model);
            return result;
        }

        /// <summary>
        ///  开始绑定生产单
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultListModel<Mch_bind_record_search> get_bind_pagelist_for_manage(mch_Bind_params_for_manage model)
        {
            var result = _service.get_bind_pagelist_for_manage(model);
            return result;
        }
        /// <summary>
        ///  发送开锁指令
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel send_open_lock(string mchid, int? boxno)
        {
            var result = _service.send_open_lock(mchid, boxno);
            return result;
        }
        /// <summary>
        /// 查询开锁状态
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel search_lock_log(string lock_id)
        {
            var result = _service.search_lock_log(lock_id);
            return result;
        }
    }
}